package com.codingman.jpademo3;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Demo4 {
	public static void main(String[] args) {
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("employee_unit");
		EntityManager em = emf.createEntityManager();

		em.getTransaction().begin();
		
		Employee4 d1 = new Employee4(101, "Ann", 100.00);
		Employee4 d2 = new Employee4(102, "Bob", 200.00);
		List<Employee4> e1 = new ArrayList<Employee4>();
		e1.add(d1);
		e1.add(d2);
		
		Music m1 = new Music(1, "Rolling in the deep");
		Music m2 = new Music(2, "Yesterday");
		List<Music> l1 = new ArrayList<Music>();
		l1.add(m1);
		l1.add(m2);
		
		d1.setMusic(l1);
		d2.setMusic(l1);
		
		m1.setEmployee(e1);
		m2.setEmployee(e1);
				
		em.persist(d1);
		em.persist(d2);
		em.persist(m1);
		em.persist(m2);
		
		em.getTransaction().commit();

		em.close();
		emf.close();
	}
}
